#include <bits/stdc++.h>
// 2025/03/14
// tag: 
// Author: Forever
using namespace std;

#define int long long
#pragma GCC -Ofast

int n, m, a[1001][1001];
string dir;

void init(){
    cin >> n >> m;
    cin >> dir;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
}

signed main()
{
    int t;
    cin >> t;
    while (t--){
        init();
        int x = 1, y = 1;
        for (char c: dir){
            if (c == 'D'){
                int sum = 0;
                for (int i = 1; i <= m; i++)
                    sum += a[x][i];
                a[x][y] = -sum;
                x++;
            }
            else{
                int sum = 0;
                for (int i = 1; i <= n; i++)
                    sum += a[i][y];
                a[x][y] = -sum;
                y++;
            }
        }
        int sum = 0;
        for (int i = 1; i <= m; i++)
            sum += a[n][i];
        a[n][m] = -sum;
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= m; j++)
                cout << a[i][j] << " ";
            cout << endl;
        }
    }
    return 0;
}